package com.dtw.ditouwang.ui.mine;

import android.media.Image;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.NotifyBean;
import com.dtw.ditouwang.models.WebApi;
import com.dtw.ditouwang.ui.OnItemClickListener;

import java.util.List;

public class UserNotifyAdapter extends RecyclerView.Adapter<UserNotifyAdapter.Holder> {
    List<NotifyBean.DataBean> notifyBeanlIst;
    private OnItemClickListener onItemClickListener;

    public UserNotifyAdapter(List<NotifyBean.DataBean> notifyBeanlIst) {
        this.notifyBeanlIst = notifyBeanlIst;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_notify_user, viewGroup, false));
    }

    @Override
    public int getItemCount() {
        return notifyBeanlIst.size();
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int i) {
        holder.name.setText(notifyBeanlIst.get(i).getNickname());
        holder.msg.setText(notifyBeanlIst.get(i).getContent());
        if(!TextUtils.isEmpty(notifyBeanlIst.get(i).getHead_img())){
            Glide.with(holder.head).load(WebApi.BaseUrl + notifyBeanlIst.get(i).getHead_img().replace("\\", "/")).into(holder.head);
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView name, msg;
        ImageView head;

        public Holder(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.text_user_name);
            msg = itemView.findViewById(R.id.text_msg);
            head = itemView.findViewById(R.id.img_head);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(onItemClickListener!=null){
                        onItemClickListener.onItemClick(0,getAdapterPosition(),0);
                    }
                }
            });
        }
    }

}
